import styles from "./index.module.scss";
import { Fragment } from "react";
import { useNavigate } from "react-router-dom";
import { connect } from "react-redux";
function NotFound({ auth }) {
  const navigate = useNavigate();
  const back_login = () => {
    // 找不到页面返回显示当前的第一个页面
    if (sessionStorage.getItem("user")) {
      let role = JSON.parse(sessionStorage.getItem("user"));
      console.log(role);
      let rolAuthor = JSON.parse(role.roleAuthority);
      let newArrRole = Object.keys(rolAuthor);
      let path = "";
      for (let i = 0; i < newArrRole.length; i++) {
        let item = newArrRole[i];
        if (rolAuthor[item].view.value) {
          path = item;
          break;
        }
      }
      navigate(path);
    }
  };
  return (
    <Fragment>
      <div className={styles.con}>
        <h1 className={styles.title}> 404</h1>
        <p>The Page not Found-找不到你要访问的页面</p>
        <button onClick={back_login}>返回</button>
      </div>
    </Fragment>
  );
}
export default connect((state) => {
  let auth = {};
  if (state.user?.roleAuthority) {
    auth = JSON.parse(state.user.roleAuthority);
  }
  return { auth };
})(NotFound);
